package com.niuwa.p2p.core.manager;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;







import org.apache.commons.collections.CollectionUtils;

import com.niuwa.p2p.entity.Dictionary;

/**
 * @author zzf
 *
 */
public class DictManager {
	
	private static DictManager dictManager = new DictManager();
	
	private Map<String, List<Dictionary>> dictMap;
	
	public static DictManager getInstance(){
		return dictManager;
	}
	
	/**
	 * 装载数据字典集合
	 * @param list
	 */
	public void init(List<Dictionary> list){
		if(CollectionUtils.isEmpty(list)){
			return;
		}else{
			dictMap = new HashMap<String, List<Dictionary>>();
			wrapperDictMap(list);
		}
	}
	
	private void wrapperDictMap(List<Dictionary> list){
		List<Dictionary> tempList = null;
		for(Dictionary dict:list){
			if(dictMap.containsKey(dict.getDictType())){
				tempList =dictMap.get(dict.getDictType());
				tempList.add(dict);
			}else{
				tempList= new ArrayList<Dictionary>();
				tempList.add(dict);
				dictMap.put(dict.getDictType(), tempList);
			}
		}
	}
	public Map<String, List<Dictionary>> getDictMap(){
		return dictMap;
	}
}
